﻿using System;
using Presentation;
using System.IO;

namespace Infrastructure
{
    public class TxtLogger: ILogger
    {
        public string fileName { get; set; }

        public TxtLogger(string logFileName = "log.txt")
        {
            fileName = logFileName;
            var writer = new StreamWriter(logFileName, false);
            writer.Close();
        }

        public void Write(string message)
        {
            var time = DateTime.Now.ToString("HH:mm:ss");
            using (var writer = new StreamWriter(fileName, true))
            {
                writer.WriteLine("[" + time + "] " + message);
                writer.Close();
            }
        }
        public string Read()
        {
            var text = "";
            using (var reader = new StreamReader(fileName))
            {
                while (!reader.EndOfStream)
                {
                    text += reader.ReadLine() + @"\n";
                }
                reader.Close();
            }
            return text;
        }
    }
}
